home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ScrollBoxLink / ScrollBoxLink.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.4 KB  |  260 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.LayoutManager;
  7. import java.awt.Panel;
  8. import java.awt.ScrollPane;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import java.net.URLEncoder;
  12.  
  13. public class ScrollBoxLink extends Applet {
  14.    private String[] url;
  15.    private String[] text;
  16.    private String target;
  17.    // $FF: renamed from: wi int
  18.    private int field_0;
  19.    // $FF: renamed from: he int
  20.    private int field_1;
  21.    private Color backColor;
  22.    public Color normalColor;
  23.    public Color enterColor;
  24.    public int justify;
  25.    public int decx;
  26.    public boolean hand;
  27.    private int heightSpace;
  28.    private AudioClip sound;
  29.    public AudioClip clicSound;
  30.    private boolean loopSound;
  31.    public boolean animated;
  32.    public int pause;
  33.  
  34.    public ScrollBoxLink() {
  35.       this.normalColor = Color.black;
  36.       this.enterColor = Color.black;
  37.       this.justify = 1;
  38.       this.decx = 0;
  39.       this.hand = true;
  40.       this.heightSpace = 10;
  41.       this.animated = false;
  42.       this.pause = 200;
  43.    }
  44.  
  45.    public String getAppletInfo() {
  46.       return "Name: ScrollBoxLink\r\nAuthor: Taiji Software";
  47.    }
  48.  
  49.    public void register() {
  50.       try {
  51.          URL u = new URL("http://www.taijisoftware.com");
  52.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  53.       } catch (Exception e) {
  54.          System.out.println(e);
  55.          this.stop();
  56.       }
  57.    }
  58.  
  59.    public void init() {
  60.       String codeBase = null;
  61.  
  62.       try {
  63.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  64.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  65.          codeBase = codeBase.toUpperCase();
  66.       } catch (Exception var10) {
  67.       }
  68.  
  69.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  70.          String regCode = ((Applet)this).getParameter("registration_code");
  71.          if (regCode == null) {
  72.             regCode = ((Applet)this).getParameter("reg_domain");
  73.             if (regCode == null) {
  74.                this.register();
  75.             } else {
  76.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  77.                   codeBase = "WWW." + codeBase;
  78.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  79.                   codeBase = codeBase.substring(4);
  80.                }
  81.  
  82.                char[] chars = new char[codeBase.length()];
  83.                codeBase.getChars(0, codeBase.length(), chars, 0);
  84.                String key = new String("haricot");
  85.                char[] chars2 = new char[key.length()];
  86.                key.getChars(0, key.length(), chars2, 0);
  87.  
  88.                for(int i = 0; i < codeBase.length(); ++i) {
  89.                   int j;
  90.                   if (i >= key.length()) {
  91.                      j = i - key.length() * (i / key.length());
  92.                   } else {
  93.                      j = i;
  94.                   }
  95.  
  96.                   chars[i] += chars2[j];
  97.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  98.                }
  99.  
  100.                String res = new String(chars);
  101.                if (!res.equalsIgnoreCase(regCode)) {
  102.                   this.register();
  103.                }
  104.             }
  105.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  106.             this.register();
  107.          }
  108.       }
  109.  
  110.       this.getParameters();
  111.  
  112.       int n;
  113.       for(n = 0; ((Applet)this).getParameter("text" + Integer.toString(n + 1)) != null; ++n) {
  114.       }
  115.  
  116.       ((Container)this).setLayout((LayoutManager)null);
  117.       ScrollPane sp = new ScrollPane(0);
  118.       ((Component)sp).setBounds(0, 0, this.field_0, this.field_1);
  119.       if (((Applet)this).getParameter("background_color") != null) {
  120.          ((Component)sp).setBackground(this.getColor("background_color"));
  121.       }
  122.  
  123.       Panel p = new Panel();
  124.       ((Container)p).setLayout((LayoutManager)null);
  125.       ((Container)sp).add(p);
  126.       ((Container)this).add(sp);
  127.       Link l = new Link("essai de link component", this, "loading", "loading");
  128.       ((Container)p).add(l);
  129.       int Lheight = ((Component)l).getPreferredSize().height;
  130.       ((Container)p).remove(l);
  131.       ((Component)p).setSize(sp.getViewportSize().width - sp.getVScrollbarWidth(), n * Lheight + (n - 1) * this.heightSpace);
  132.  
  133.       for(int i = 0; i < n; ++i) {
  134.          Link ll = new Link(((Applet)this).getParameter("text" + Integer.toString(i + 1)), this, ((Applet)this).getParameter("link" + Integer.toString(i + 1)), ((Applet)this).getParameter("status_bar_text" + Integer.toString(i + 1)));
  135.          ((Container)p).add(ll);
  136.          ((Component)ll).setBounds(this.decx, i * (Lheight + this.heightSpace), sp.getViewportSize().width - sp.getVScrollbarWidth() - this.decx, Lheight);
  137.       }
  138.  
  139.       if (this.sound != null) {
  140.          if (this.loopSound) {
  141.             this.sound.loop();
  142.             return;
  143.          }
  144.  
  145.          this.sound.play();
  146.       }
  147.  
  148.    }
  149.  
  150.    public void stop() {
  151.       if (this.sound != null) {
  152.          this.sound.stop();
  153.       }
  154.  
  155.    }
  156.  
  157.    public void getParameters() {
  158.       this.field_0 = ((Component)this).getSize().width;
  159.       this.field_1 = ((Component)this).getSize().height;
  160.       String s = ((Applet)this).getParameter("justify");
  161.       if (s != null) {
  162.          this.justify = Integer.parseInt(s);
  163.       }
  164.  
  165.       s = ((Applet)this).getParameter("pause");
  166.       if (s != null) {
  167.          this.pause = Integer.parseInt(s);
  168.       }
  169.  
  170.       s = ((Applet)this).getParameter("width_offset");
  171.       if (s != null) {
  172.          this.decx = Integer.parseInt(s);
  173.       }
  174.  
  175.       s = ((Applet)this).getParameter("height_space");
  176.       if (s != null) {
  177.          this.heightSpace = Integer.parseInt(s);
  178.       }
  179.  
  180.       s = ((Applet)this).getParameter("hand");
  181.       if (s != null && s.equals("0")) {
  182.          this.hand = false;
  183.       }
  184.  
  185.       s = ((Applet)this).getParameter("animated");
  186.       if (s != null && s.equals("1")) {
  187.          this.animated = true;
  188.       }
  189.  
  190.       if (((Applet)this).getParameter("normal_color") != null) {
  191.          this.normalColor = this.getColor("normal_color");
  192.       }
  193.  
  194.       if (((Applet)this).getParameter("enter_color") != null) {
  195.          this.enterColor = this.getColor("enter_color");
  196.       }
  197.  
  198.       s = ((Applet)this).getParameter("sound_name");
  199.       if (s != null) {
  200.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  201.       }
  202.  
  203.       s = ((Applet)this).getParameter("loop_sound");
  204.       if (s != null) {
  205.          if (s.equals("yes")) {
  206.             this.loopSound = true;
  207.          } else {
  208.             this.loopSound = false;
  209.          }
  210.       }
  211.  
  212.       s = ((Applet)this).getParameter("clic_sound_name");
  213.       if (s != null) {
  214.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  215.       }
  216.  
  217.    }
  218.  
  219.    private Color getColor(String param) {
  220.       String s = ((Applet)this).getParameter(param);
  221.       if (s != null) {
  222.          if (s.substring(0, 1).equals("#")) {
  223.             s = s.substring(1);
  224.             int i = Integer.parseInt(s, 16);
  225.             return new Color(i);
  226.          } else {
  227.             return null;
  228.          }
  229.       } else {
  230.          return null;
  231.       }
  232.    }
  233.  
  234.    public URL giveURL(String url) {
  235.       try {
  236.          if (url.toUpperCase().startsWith("HTTP")) {
  237.             return new URL(url);
  238.          } else if (url.toUpperCase().startsWith("FTP")) {
  239.             int p = url.indexOf(":");
  240.             int p2 = url.indexOf(":", p + 1);
  241.             if (p2 != -1) {
  242.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  243.             }
  244.  
  245.             p = url.indexOf("%40");
  246.             if (p != -1) {
  247.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  248.             }
  249.  
  250.             return new URL(url);
  251.          } else {
  252.             return new URL(((Applet)this).getCodeBase(), url);
  253.          }
  254.       } catch (MalformedURLException e) {
  255.          System.out.println(e);
  256.          return null;
  257.       }
  258.    }
  259. }
  260.